﻿/***************************************************************************
	Copyright (C) 2010 RapidWebDev Organization (Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@gmail.com)

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***************************************************************************/

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml.Serialization;
using BaoJianSoft.Common;
using BaoJianSoft.Membership;
using BaoJianSoft.Web.Extensions;
using BaoJianSoft.Web.Extensions.Controls;

namespace BaoJianSoft.Web.Extensions.DynamicPages
{
	/// <summary>
	/// Event argument fires when querying.
	/// </summary>
	[Serializable]
	public class QueryEventArgs : EventArgs
	{
		/// <summary>
		/// Gets querying criterias.
		/// </summary>
		public Collection<QueryCriteria> Criterias { get; set; }

		/// <summary>
		/// Get predicate generated by query panel.
		/// </summary>
		public string Predicate { get; set; }

		/// <summary>
		/// Get parameters for predicate.
		/// </summary>
		public object[] PredicateParameters { get; set; }

		/// <summary>
		/// Construct query event argument.
		/// </summary>
		public QueryEventArgs() { }

		/// <summary>
		/// Construct query event argument.
		/// </summary>
		/// <param name="criterias"></param>
		/// <param name="predicate"></param>
		/// <param name="predicateParameters"></param>
		public QueryEventArgs(IEnumerable<QueryCriteria> criterias, string predicate, object[] predicateParameters)
		{
			this.Criterias = new Collection<QueryCriteria>(criterias.ToList());
			this.Predicate = predicate;
			this.PredicateParameters = predicateParameters;
		}

		/// <summary>
		/// 将当前的QueryEventArgs序列化成字符串
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			XmlSerializer serializer = new XmlSerializer(this.GetType());
			StringBuilder output = new StringBuilder();
			using (StringWriter stringWriter = new StringWriter(output, CultureInfo.InvariantCulture))
			{
				serializer.Serialize(stringWriter, this);
			}

			return output.ToString();
		}
	}
}
